package com.eazy.lkv2.web.controller.blog;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.eazy.lkv2.web.entity.blog.Friend;
import com.eazy.lkv2.web.service.blog.FriendService;

@Controller
@RequestMapping("friends")
public class FriendController {

	@Autowired
	private FriendService friendService;

	@RequestMapping(value = "/list")
	public String list(HttpSession session, ModelMap map) {
		List<Friend> data = friendService.getAllFriendList();
		map.put("data", data);
		return "/blog/admin/friends/friends_list";
	}

	@RequestMapping(value = "/addJump", method = RequestMethod.POST)
	public String addPartner(Friend friend) {
		friendService.create(friend);
		return "redirect:/friends/list";
	}

	@RequestMapping(value = "/editJump", method = RequestMethod.POST)
	public String editJump(Friend friend) {
		friendService.update(friend);
		return "redirect:/friends/list";
	}

	/**
	 * 跳转编辑页面
	 */
	@RequestMapping(value = "/editJump/{id}")
	public String editJump(ModelMap map, @PathVariable String id) {
		map.put("data", friendService.findById(Integer.valueOf(id)));
		return "/blog/admin/friends/friends_update";
	}

	/**
	 * 跳转新增页面
	 */
	@RequestMapping(value = "/addJump")
	public String addJump(ModelMap map) {
		return "/blog/admin/friends/friends_add";
	}

}
